import { pushCreepToTargetCreepList } from '../../tools/tools/creepTool'
import eventManager from './eventManager'
import { eventMap } from './eventMap'
const spawnEvent = {
    spawnCreep: function (params) {
        const { spawnID, taskID, targetID } = params
        let spawn = Game.getObjectById(spawnID)
        let creepName = spawn.spawning.name
        pushCreepToTargetCreepList(creepName)   // 对creep及相关目标的数据更新
        // console.log(`生产creep的任务出现异常${creepName},任务ID:${taskID}`);
        // 将反馈完成任务
        eventManager.add(`报告${spawn.name}完成生产${spawn.spawning.name}任务`, spawn.spawning.needTime + 1, eventMap.finishTask, { taskID: taskID, roomName: spawn.pos.roomName })
        // 获取当前生产creep耗时
        eventManager.add(`切换${spawn.name}的工作状态`, spawn.spawning.needTime + 1, eventMap.objToSleep, { objID: spawnID, to: false })
        // 将creep推送到工作岗位
        if (targetID) {
            eventManager.add(`推送${creepName}到工作岗位`, spawn.spawning.needTime + 1, eventMap.pushCreepToWork, { creepName: creepName, targetID: targetID })
        }

    }
}

export default spawnEvent